
use "$cleaned/all_s6_cleaned.dta", clear


**************************************
*	table 1
**************************************

*balance test
global balance AGE female stem POINTS2_mock  std_principal2_mock std_subsidiary2_mock
reg treatment  $balance school1-school11
test AGE female stem
*can't reject 0

eststo placebo:  estpost summarize ///
    $balance if treatment == 0
eststo treatment:  estpost summarize ///
    $balance if treatment == 1
eststo diff:  estpost ttest ///
   $balance, by(treatment) unequal

   esttab  placebo treatment diff using "${output}/table1b.tex", cells("mean(pattern(1 1 0) fmt(2)) sd(pattern(1 1 0)) b(star pattern(0 0 1) fmt(2)) p(pattern(0 0 1) par fmt(2))")label replace

gen std_principal2_mock_miss=0
replace std_principal2_mock_miss=1 if std_principal2_mock==.
replace std_principal2_mock=POINTS2_mock if std_principal2_mock==.
gen std_subsidiary2_mock_miss=0
replace std_subsidiary2_mock_miss=1 if std_subsidiary2_mock==.
replace std_subsidiary2_mock=POINTS2_mock if std_subsidiary2_mock==.


**************************************
*	table 3
**************************************

reghdfe std_POINTS2 treatment school1-school11 , vce(robust) $reghdfe
outreg2 using "${output}/table3.tex", dec(2) title(Impact of treatment assignment on standardized test scores) keep(std_POINTS2 treatment) replace label
reghdfe std_POINTS2 treatment school1-school11 ${controls} POINTS2_mock, vce(robust) $reghdfe
outreg2 using "${output}/table3.tex", dec(2) title(Impact of treatment assignment on standardized test scores) keep(std_POINTS2 treatment ${controls} POINTS2_mock) label

reghdfe std_principal2 treatment school1-school11 , vce(robust) $reghdfe
outreg2 using "${output}/table3.tex", dec(2) title(Impact of treatment assignment on standardized test scores) keep(std_principal2 treatment )  label
reghdfe std_principal2 treatment school1-school11 ${controls} std_principal2_mock std_principal2_mock_miss, vce(robust) $reghdfe
outreg2 using "${output}/table3.tex", dec(2) title(Impact of treatment assignment on standardized test scores) keep(std_principal2 treatment ${controls} std_principal2_mock) label

reghdfe std_subsidiary2 treatment school1-school11 , vce(robust) $reghdfe
outreg2 using "${output}/table3.tex", dec(2) title(Impact of treatment assignment on standardized test scores) keep(std_subsidiary2 treatment ) label
reghdfe std_subsidiary2 treatment school1-school11  ${controls}  std_subsidiary2_mock std_subsidiary2_mock_miss, vce(robust) $reghdfe
outreg2 using "${output}/table3.tex", dec(2) title(Impact of treatment assignment on standardized test scores) keep(std_subsidiary2 treatment ${controls} std_subsidiary2_mock)  label

**************************************
*	table 5
**************************************

preserve 
local i=1
tempfile tf`i' 
reghdfe std_POINTS2 treatment  treatment_female      female stem POINTS2_mock   school1-school11 ${controls}, $reghdfe vce(robust)
parmest, format(p %12.9f) saving(`tf`i'',replace) idn(`i')
local i=`i'+1
tempfile tf`i' 
reghdfe std_POINTS2 treatment  treatment_female  treatment_stem  treatment_female_stem female_stem female stem POINTS2_mock   school1-school11 ${controls}, $reghdfe vce(robust)
parmest, format(p %12.9f) saving(`tf`i'',replace) idn(`i')

local i=`i'+1
tempfile tf`i' 
reghdfe std_principal2 treatment  treatment_female      female stem std_principal2_mock   school1-school11 ${controls}, $reghdfe vce(robust)
parmest, format(p %12.9f) saving(`tf`i'',replace) idn(`i')
local i=`i'+1
tempfile tf`i' 
reghdfe std_principal2 treatment  treatment_female  treatment_stem  treatment_female_stem female_stem female stem std_principal2_mock std_principal2_mock_miss  school1-school11 ${controls}, vce(robust) $reghdfe
parmest, format(p %12.9f) saving(`tf`i'',replace) idn(`i')

local i=`i'+1
tempfile tf`i' 
reghdfe std_subsidiary2 treatment  treatment_female  female stem std_subsidiary2_mock   school1-school11 ${controls}, $reghdfe vce(robust)
parmest, format(p %12.9f) saving(`tf`i'',replace) idn(`i')
local i=`i'+1
tempfile tf`i' 
reghdfe std_subsidiary2 treatment  treatment_female  treatment_stem  treatment_female_stem female_stem female stem std_subsidiary2_mock std_subsidiary2_mock_miss  school1-school11 ${controls}, vce(robust) $reghdfe
parmest, format(p %12.9f) saving(`tf`i'',replace) idn(`i')


dsconcat  `tf1'
keep if parm=="treatment"  | parm=="treatment_female"   
keep p idnum
qqvalue p, method(yekutieli) qvalue(q)
replace q=0.99 if q==1
format q %8.2f
replace q=round(q, 0.01)
*qqvalue p, method(bonferroni) qvalue(q2)
foreach x of numlist 1/2 {
global Tq1`x'=q[`x']
display ${Tq1`x'}
}

dsconcat  `tf2'
keep if parm=="treatment" | parm=="treatment_female"   | parm=="treatment_stem"  | parm=="treatment_female_stem"
keep p idnum
qqvalue p, method(yekutieli) qvalue(q)
replace q=0.99 if q==1
format q %8.2f
replace q=round(q, 0.01)
*qqvalue p, method(bonferroni) qvalue(q2)
foreach x of numlist 1/4 {
global Tq2`x'=q[`x']
display ${Tq2`x'}
}

dsconcat  `tf3'
keep if parm=="treatment"  | parm=="treatment_female"   
keep p idnum
qqvalue p, method(yekutieli) qvalue(q)
replace q=0.99 if q==1
format q %8.2f
replace q=round(q, 0.01)
*qqvalue p, method(bonferroni) qvalue(q2)
foreach x of numlist 1/2 {
global Tq3`x'=q[`x']
display ${Tq3`x'}
}

dsconcat  `tf4'
keep if parm=="treatment" | parm=="treatment_female"   | parm=="treatment_stem"  | parm=="treatment_female_stem"
keep p idnum
qqvalue p, method(yekutieli) qvalue(q)
replace q=0.99 if q==1
format q %8.2f
replace q=round(q, 0.01)
*qqvalue p, method(bonferroni) qvalue(q2)
foreach x of numlist 1/4 {
global Tq4`x'=q[`x']
display ${Tq4`x'}
}

dsconcat  `tf5'
keep if parm=="treatment" | parm=="treatment_female"   
keep p idnum
qqvalue p, method(yekutieli) qvalue(q)
replace q=0.99 if q==1
format q %8.2f
replace q=round(q, 0.01)
*qqvalue p, method(bonferroni) qvalue(q2)
foreach x of numlist 1/2 {
global Tq5`x'=q[`x']
display ${Tq5`x'}
}

dsconcat  `tf6'
keep if parm=="treatment" | parm=="treatment_female"   | parm=="treatment_stem"  | parm=="treatment_female_stem"
keep p idnum
qqvalue p, method(yekutieli) qvalue(q)
replace q=0.99 if q==1
format q %8.2f
replace q=round(q, 0.01)
*qqvalue p, method(bonferroni) qvalue(q2)
foreach x of numlist 1/4 {
global Tq6`x'=q[`x']
display ${Tq6`x'}
}

restore

reghdfe std_POINTS2 treatment  treatment_female      female stem POINTS2_mock   school1-school11 ${controls}, $reghdfe vce(robust)
lincom treatment + treatment_female   //female 
local F2c = r(estimate)
local F2se = r(se)
test  treatment + treatment_female  = 0
local p_value2=r(p)
outreg2 using "${output}/table5.tex", dec(2) title(Impact of treatment assignment on standardized test scores) adec(2) ///
keep(treatment  treatment_female  treatment_stem   female_stem female stem POINTS2_mock $controls ) ///
addstat(female sum , `F2c', SE, `F2se', pval, `p_value2', qvalue interaction f, ${Tq12}, qvalue, ${Tq11})  replace

reghdfe std_POINTS2 treatment  treatment_female  treatment_stem  treatment_female_stem female_stem female stem POINTS2_mock   school1-school11 ${controls}, $reghdfe vce(robust)
lincom treatment + treatment_female + treatment_female_stem +treatment_stem  //female stem
local F1c = r(estimate)
local F1se = r(se)
test  treatment + treatment_female + treatment_female_stem +treatment_stem = 0
local p_value1=r(p)
lincom treatment + treatment_female   //female non-stem
local F2c = r(estimate)
local F2se = r(se)
test  treatment + treatment_female  = 0
local p_value2=r(p)
lincom treatment  +treatment_stem  //male stem
local F3c = r(estimate)
local F3se = r(se)
test  treatment  +treatment_stem = 0
local p_value3=r(p)
lincom treatment //male -non- stem
local F4c = r(estimate)
local F4se = r(se)
test  treatment = 0
local p_value4=r(p)
outreg2 using "${output}/table5.tex", dec(2) title(Impact of treatment assignment on standardized test scores) adec(2) ///
keep(treatment  treatment_female  treatment_stem  treatment_female_stem female_stem female stem POINTS2_mock $controls ) ///
addstat(female stem, `F1c', SE, `F1se', pval, `p_value1', female nonstem, `F2c', SE, `F2se', pval, `p_value2', male stem, `F3c', SE, `F3se', pval, `p_value3', male nonstem, `F4c', SE, `F4se', pval, `p_value4', qvalue interaction f, ${Tq22}, qvalue, ${Tq21}, qvalue interaction s, ${Tq23}, qvalue interaction fs, ${Tq24}) 

reghdfe std_principal2 treatment  treatment_female      female stem std_principal2_mock   school1-school11 ${controls}, $reghdfe vce(robust)
lincom treatment + treatment_female   //female 
local F2c = r(estimate)
local F2se = r(se)
test  treatment + treatment_female  = 0
local p_value2=r(p)
outreg2 using "${output}/table5.tex", dec(2) title(Impact of treatment assignment on standardized test scores) adec(2) ///
keep(treatment  treatment_female  treatment_stem   female_stem female stem std_principal2_mock $controls ) ///
addstat(female sum , `F2c', SE, `F2se', pval, `p_value2', qvalue interaction f, ${Tq32}, qvalue, ${Tq31})  

reghdfe std_principal2 treatment  treatment_female  treatment_stem  treatment_female_stem female_stem female stem std_principal2_mock std_principal2_mock_miss  school1-school11 ${controls}, vce(robust) $reghdfe
lincom treatment + treatment_female + treatment_female_stem +treatment_stem  //female stem
local F1c = r(estimate)
local F1se = r(se)
test  treatment + treatment_female + treatment_female_stem +treatment_stem = 0
local p_value1=r(p)
lincom treatment + treatment_female   //female non-stem
local F2c = r(estimate)
local F2se = r(se)
test  treatment + treatment_female  = 0
local p_value2=r(p)
lincom treatment  +treatment_stem  //male stem
local F3c = r(estimate)
local F3se = r(se)
test  treatment  +treatment_stem = 0
local p_value3=r(p)
lincom treatment //male -non- stem
local F4c = r(estimate)
local F4se = r(se)
test  treatment = 0
local p_value4=r(p)
test  treatment_female + treatment =treatment + treatment+stem
outreg2 using "${output}/table5.tex", dec(2) title(Impact of treatment assignment on standardized test scores) adec(2) ///
keep(treatment  treatment_female  treatment_stem  treatment_female_stem female_stem female stem std_principal2_mock $controls ) ///
addstat(female stem, `F1c', SE, `F1se', pval, `p_value1', female nonstem, `F2c', SE, `F2se', pval, `p_value2', male stem, `F3c', SE, `F3se', pval, `p_value3', male nonstem, `F4c', SE, `F4se', pval, `p_value4', qvalue interaction f, ${Tq42}, qvalue, ${Tq41}, qvalue interaction s, ${Tq43}, qvalue interaction fs, ${Tq44}) 

reghdfe std_subsidiary2 treatment  treatment_female  female stem std_subsidiary2_mock   school1-school11 ${controls}, $reghdfe vce(robust)
lincom treatment + treatment_female   //female 
local F2c = r(estimate)
local F2se = r(se)
test  treatment + treatment_female  = 0
local p_value2=r(p)
outreg2 using "${output}/table5.tex", dec(2) title(Impact of treatment assignment on standardized test scores) adec(2) ///
keep(treatment  treatment_female  treatment_stem   female_stem female stem std_subsidiary2_mock $controls ) ///
addstat(female sum , `F2c', SE, `F2se', pval, `p_value2', qvalue interaction f, ${Tq52}, qvalue, ${Tq51}) 

reghdfe std_subsidiary2 treatment  treatment_female  treatment_stem  treatment_female_stem female_stem female stem std_subsidiary2_mock std_subsidiary2_mock_miss  school1-school11 ${controls}, vce(robust) $reghdfe
lincom treatment + treatment_female + treatment_female_stem +treatment_stem  //female stem
local F1c = r(estimate)
local F1se = r(se)
test  treatment + treatment_female + treatment_female_stem +treatment_stem = 0
local p_value1=r(p)
lincom treatment + treatment_female   //female non-stem
local F2c = r(estimate)
local F2se = r(se)
test  treatment + treatment_female  = 0
local p_value2=r(p)
lincom treatment  +treatment_stem  //male stem
local F3c = r(estimate)
local F3se = r(se)
test  treatment  +treatment_stem = 0
local p_value3=r(p)
lincom treatment //male -non- stem
local F4c = r(estimate)
local F4se = r(se)
test  treatment = 0
local p_value4=r(p)
test treatment+treatment_stem=treatment+treatment_stem+ treatment_female+treatment_female_stem // female stem=male stem
test treatment=treatment+treatment_female // female non-stem=male  non-stem
test treatment+treatment_stem+ treatment_female+treatment_female_stem=treatment+treatment_female // female stem=female non-stem
test treatment= treatment+ treatment_stem // male non-stem = male-stem 
test treatment+treatment_female = treatment + treatment_stem //female non-stem=male stem
outreg2 using "${output}/table5.tex", dec(2) title(Impact of treatment assignment on standardized test scores) adec(2) ///
keep(treatment  treatment_female  treatment_stem  treatment_female_stem female_stem female stem std_subsidiary2_mock $controls ) ///
addstat(female stem, `F1c', SE, `F1se', pval, `p_value1', female nonstem, `F2c', SE, `F2se', pval, `p_value2', male stem, `F3c', SE, `F3se', pval, `p_value3', male nonstem, `F4c', SE, `F4se', pval, `p_value4', qvalue interaction f, ${Tq62}, qvalue, ${Tq61}, qvalue interaction s, ${Tq63}, qvalue interaction fs, ${Tq64})  


**************************************
*	table 7
**************************************

reg UNI treatment school1-school11 POINTS2_mock AGE female stem, vce(robust) 
sum UNI if treatment==0
local mean =r(mean)
outreg2 using "${output}/table7.tex", dec(2) adec(2) addstat(mean, `mean') keep(treatment UNI POINTS2_mock AGE female stem)

reghdfe UNI treatment treatment_female female school1-school11 POINTS2_mock AGE stem, vce(robust) $reghdfe
sum UNI if treatment==0 & female==1
local mean =r(mean)
outreg2 using "${output}/table7.tex", dec(2) adec(2) addstat(mean, `mean') keep (treatment treatment_female UNI POINTS2_mock AGE female stem)

reg uni_applied treatment female  school1-school11 POINTS2_mock stem , vce(robust) 
sum uni_applied if treatment==0 
local mean =r(mean)
outreg2 using "${output}/table7.tex", dec(2) adec(2) addstat(mean, `mean')  keep (treatment uni_applied POINTS2_mock AGE female stem)

reg uni_applied treatment female treatment_female school1-school11 POINTS2_mock stem , vce(robust) 
sum uni_applied if treatment==0 & female==1
local mean =r(mean)
outreg2 using "${output}/table7.tex", dec(2) adec(2) addstat(mean, `mean')  keep (treatment treatment_female uni_applied POINTS2_mock AGE female stem)

**************************************
*	Figure A3
**************************************

reg std_POINTS2  school1-school11 AGE stem female , vce(robust) 
predict covariates_effect_points
gen adjusted_score_points=std_POINTS2-covariates_effect_points
twoway (kdensity adjusted_score_points if treatment==1,  color(gray)) (kdensity adjusted_score_points if treatment==0, fcolor(none) lcolor(black)), legend(order(1 "Treated" 2 "Placebo" )) ylabel(, grid)
graph export "${output}/fig3_points.png", as(png) replace
ksmirnov adjusted_score_points, by(treatment)

reg std_principal2  school1-school11 AGE stem female , vce(robust) 
predict covariates_effect_prin
gen adjusted_score_prin=std_principal2-covariates_effect_prin
twoway (kdensity adjusted_score_prin if treatment==1,  color(gray)) (kdensity adjusted_score_prin if treatment==0, fcolor(none) lcolor(black)), legend(order(1 "Treated" 2 "Placebo" )) ylabel(, grid)
graph export "${output}/fig3_prin.png", as(png) replace
ksmirnov adjusted_score_prin, by(treatment)

reg std_subsidiary2  school1-school11 AGE stem female , vce(robust) 
predict covariates_effect_sub
gen adjusted_score_sub=std_subsidiary2-covariates_effect_sub
twoway (kdensity adjusted_score_sub if treatment==1,  color(gray)) (kdensity adjusted_score_sub if treatment==0, fcolor(none) lcolor(black)), legend(order(1 "Treated" 2 "Placebo" )) ylabel(, grid)
graph export "${output}/fig3_sub.png", as(png) replace
ksmirnov adjusted_score_sub, by(treatment)



**************************************
*	Table A7
**************************************

ologit POINTS treatment school1-school11  POINTS_mock, vce(robust)
 margins,  dydx(treatment)  post
outreg2 using "${output}/table_A7.tex",  dec(3)  title(Impact of treatment on overall grade) replace

ologit principal treatment school1-school11  POINTS_mock, vce(robust)
 margins,  dydx(treatment)  post
outreg2 using "${output}/table_A7.tex",  dec(3)  title(Impact of treatment on overall grade) 


ologit subsidiary_gep treatment school1-school11 POINTS_mock  , vce(robust)
 margins,  dydx(treatment)  post
outreg2 using "${output}/table_A7.tex",  dec(3)  title(Impact of treatment on overall grade) 

**************************************
*	Table A10
**************************************

local z=1
foreach y of global subgroup2  {
local i=1
tempfile tf`y'`i' 
reghdfe std_POINTS2 POINTS2_mock treatment treatment_`y' school1-school11 $controls `y', vce(robust)  $reghdfe
parmest, format(p %12.9f) saving(`tf`y'`i'',replace) idn(`i')
local i=`i'+1
tempfile tf`y'`i' 
reghdfe std_principal2 std_principal2_mock std_principal2_mock_miss treatment treatment_`y' `y' school1-school11 $controls , vce(robust)  $reghdfe
parmest, format(p %12.9f) saving(`tf`y'`i'',replace) idn(`i')
local i=`i'+1
tempfile tf`y'`i' 
if `z'==2 {
reghdfe std_subsidiary2  std_subsidiary2_mock std_subsidiary2_mock_miss treatment treatment_`y'_sub  $controls `y'_sub school1-school11 ${controls}, vce(robust) $reghdfe
parmest, format(p %12.9f) saving(`tf`y'`i'',replace) idn(`i')
} 
else {
reghdfe std_subsidiary2  std_subsidiary2_mock std_subsidiary2_mock_miss treatment treatment_`y'  $controls `y' school1-school11 ${controls}, vce(robust) $reghdfe
parmest, format(p %12.9f) saving(`tf`y'`i'',replace) idn(`i')	
	
}
local z=`z'+1
}

preserve 

local j=1
foreach y of global subgroup2  {
dsconcat `tf`y'1' `tf`y'2' `tf`y'3' 

keep if parm=="treatment_`y'" | parm=="treatment_`y'_sub"
keep p idnum
qqvalue p, method(yekutieli) qvalue(q)
replace q=0.99 if q==1
format q %12.0g
*qqvalue p, method(bonferroni) qvalue(q2)
foreach x of numlist 1/3 {
global Tbq`j'`x'=q[`x']
display ${Tbq`j'`x'}
}

dsconcat `tf`y'1' `tf`y'2' `tf`y'3' 
keep if parm=="treatment"
keep p idnum
qqvalue p, method(yekutieli) qvalue(q)
replace q=0.99 if q==1
format q %12.0g
*qqvalue p, method(bonferroni) qvalue(q2)
foreach x of numlist 1/3 {
global Tq`j'`x'=q[`x']
display ${Tq`j'`x'}
}
local j=`j'+1
}
restore


local i=1
foreach x of varlist stem { 
reghdfe std_POINTS2 POINTS2_mock treatment treatment_`x' school1-school11 $controls `x', vce(robust)  $reghdfe
lincom treatment_`x' + treatment
local F1c = r(estimate)
local F1se = r(se)
test `x' + treatment_`x' + treatment = `x'
local p_value=r(p)
if `i'==1 {
outreg2 using "${output}/table_A10.tex", dec(2) title(Impact of treatment assignment on standardized test scores) keep(std_POINTS2 treatment treatment_`x' `x' ${controls} POINTS2_mock) addstat(treated, `F1c', SE , `F1se', p_value, `p_value', qvalue interaction, ${Tbq`i'1}, qvalue, ${Tq`i'1}) replace label adec(2)
}
else {
outreg2 using "${output}/table_A10.tex", dec(2) title(Impact of treatment assignment on standardized test scores) keep(std_POINTS2 treatment treatment_`x' `x'  ${controls} POINTS2_mock) addstat(treated, `F1c', SE , `F1se', p_value, `p_value', qvalue interaction, ${Tbq`i'1}, qvalue, ${Tq`i'1})  label adec(2)
}
reghdfe std_principal2 std_principal2_mock std_principal2_mock_miss treatment treatment_`x' `x' school1-school11 $controls , vce(robust)  $reghdfe
lincom treatment_`x' + treatment
local F1c = r(estimate)
local F1se = r(se)
test `x' + treatment_`x' + treatment = `x'
local p_value=r(p)
outreg2 using "${output}/table_A10.tex", dec(2) title(Impact of treatment assignment on standardized test scores) keep(std_principal2 treatment treatment_`x' `x' ${controls} std_principal2_mock) addstat(treated, `F1c', SE , `F1se', p_value, `p_value', qvalue interaction, ${Tbq`i'2}, qvalue, ${Tq`i'2})  label adec(2)

reghdfe std_subsidiary2  std_subsidiary2_mock std_subsidiary2_mock_miss treatment treatment_`x'  $controls `x' school1-school11 ${controls}, vce(robust) $reghdfe
lincom treatment_`x' + treatment
local F1c = r(estimate)
local F1se = r(se)
test `x' + treatment_`x' + treatment = `x'
local p_value = r(p)
outreg2 using "${output}/table_A10.tex", dec(2) title(Impact of treatment assignment on standardized test scores) keep(std_subsidiary2 treatment treatment_`x' `x' ${controls} std_subsidiary2_mock) addstat(treated, `F1c',SE , `F1se', p_value, `p_value', qvalue interaction, ${Tbq`i'3}, qvalue, ${Tq`i'3}) label adec(2)
local i=`i'+1
}

foreach x of varlist below_median_mock { 
reghdfe std_POINTS2 POINTS2_mock treatment treatment_`x' school1-school11 $controls `x', vce(robust)  $reghdfe
lincom treatment_`x' + treatment
local F1c = r(estimate)
local F1se = r(se)
test `x' + treatment_`x' + treatment = `x'
local p_value=r(p)
if `i'==1 {
outreg2 using "${output}/table_A10.tex", dec(2) title(Impact of treatment assignment on standardized test scores) keep(std_POINTS2 treatment treatment_`x' `x' ${controls} POINTS2_mock) addstat(treated, `F1c', SE , `F1se', p_value, `p_value', qvalue interaction, ${Tbq`i'1}, qvalue, ${Tq`i'1}) replace label adec(2)
}
else {
outreg2 using "${output}/table_A10.tex", dec(2) title(Impact of treatment assignment on standardized test scores) keep(std_POINTS2 treatment treatment_`x' `x'  ${controls} POINTS2_mock) addstat(treated, `F1c', SE , `F1se', p_value, `p_value', qvalue interaction, ${Tbq`i'1}, qvalue, ${Tq`i'1})  label adec(2)
}
reghdfe std_principal2 std_principal2_mock std_principal2_mock_miss treatment treatment_`x' `x' school1-school11 $controls , vce(robust)  $reghdfe
lincom treatment_`x' + treatment
local F1c = r(estimate)
local F1se = r(se)
test `x' + treatment_`x' + treatment = `x'
local p_value=r(p)
outreg2 using "${output}/table_A10.tex", dec(2) title(Impact of treatment assignment on standardized test scores) keep(std_principal2 treatment treatment_`x' `x' ${controls} std_principal2_mock) addstat(treated, `F1c', SE , `F1se', p_value, `p_value', qvalue interaction, ${Tbq`i'2}, qvalue, ${Tq`i'2})  label adec(2)

reghdfe std_subsidiary2  std_subsidiary2_mock std_subsidiary2_mock_miss treatment treatment_`x'_sub  $controls `x'_sub school1-school11 ${controls}, vce(robust) $reghdfe
lincom treatment_`x' + treatment
local F1c = r(estimate)
local F1se = r(se)
test `x' + treatment_`x' + treatment = `x'
local p_value = r(p)
outreg2 using "${output}/table_A10.tex", dec(2) title(Impact of treatment assignment on standardized test scores) keep(std_subsidiary2 treatment treatment_`x' `x' ${controls} std_subsidiary2_mock) addstat(treated, `F1c',SE , `F1se', p_value, `p_value', qvalue interaction, ${Tbq`i'3}, qvalue, ${Tq`i'3}) label adec(2)
local i=`i'+1
}


**************************************
*	Table A11
**************************************
xtile decile_mock=POINTS_mock , nq(10)
tab decile_mock, gen(decile_mock_)
foreach x of varlist decile_mock* {
gen treatment_`x'=treatment*`x'
}
xtile subdecile_mock=subsidiary_gep_mock , nq(10)
tab subdecile_mock, gen(subdecile_mock_)
foreach x of varlist subdecile_mock* {
gen treatment_`x'=treatment*`x'
}

reghdfe std_POINTS2  treatment treatment_decile_mock_1-treatment_decile_mock_8 decile_mock_1-decile_mock_8 AGE stem female, vce(robust) $reghdfe
foreach x of varlist decile_mock_1 - decile_mock_8 {
lincom treatment_`x' + treatment
local F1c`x' = r(estimate)
local F1se`x' = r(se)
test  treatment_`x' + treatment = 0
local p_value`x'=r(p)
}
outreg2 using  "${output}/Table_A11.tex",  dec(2) keep(treatment treatment*) adec(2) replace addstat(decile 1, `F1cdecile_mock_1', se1 , `F1sedecile_mock_1', p_value1, `p_valuedecile_mock_1', decile 2, `F1cdecile_mock_2', se2 , `F1sedecile_mock_2', p_value1, `p_valuedecile_mock_2',decile 3, `F1cdecile_mock_3', se3 , `F1sedecile_mock_3', p_value3, `p_valuedecile_mock_3',decile 4, `F1cdecile_mock_4', se4 , `F1sedecile_mock_4', p_value4, `p_valuedecile_mock_4',decile 5, `F1cdecile_mock_5',  se5, `F1sedecile_mock_5', p_value5, `p_valuedecile_mock_5',decile 6, `F1cdecile_mock_6',se6  , `F1sedecile_mock_6', p_value6, `p_valuedecile_mock_6',decile 7, `F1cdecile_mock_7', se7, `F1sedecile_mock_7', p_value7, `p_valuedecile_mock_7',decile 8, `F1cdecile_mock_8', se8 , `F1sedecile_mock_8', p_value8, `p_valuedecile_mock_8')


reghdfe std_subsidiary2   treatment treatment_subdecile_mock_1-treatment_subdecile_mock_8  subdecile_mock_1-subdecile_mock_8 AGE stem female std_subsidiary2_mock, vce(robust) $reghdfe
local i=1
foreach x of varlist subdecile_mock_1 - subdecile_mock_8 {
lincom treatment_`x' + treatment
local F1c`x' = r(estimate)
local F1se`x' = r(se)
test  treatment_`x' + treatment = 0
local p_value`x'=r(p)
}
outreg2 using  "${output}/table_A11.tex",  dec(2) keep(treatment treatment*) adec(2) addstat(subdecile 1, `F1csubdecile_mock_1', se1 , `F1sesubdecile_mock_1', p_value1, `p_valuesubdecile_mock_1', subdecile 2, `F1csubdecile_mock_2', se2 , `F1sesubdecile_mock_2', p_value2, `p_valuesubdecile_mock_2',subdecile 3, `F1csubdecile_mock_3', se3 , `F1sesubdecile_mock_3', p_value3, `p_valuesubdecile_mock_3',subdecile 4, `F1csubdecile_mock_4', se4 , `F1sesubdecile_mock_4', p_value4, `p_valuesubdecile_mock_4',subdecile 5, `F1csubdecile_mock_5',  se5, `F1sesubdecile_mock_5', p_value5, `p_valuesubdecile_mock_5',subdecile 6, `F1csubdecile_mock_6',se6  , `F1sesubdecile_mock_6', p_value6, `p_valuesubdecile_mock_6',subdecile 7, `F1csubdecile_mock_7', se7, `F1sesubdecile_mock_7', p_value7, `p_valuesubdecile_mock_7',subdecile 8, `F1csubdecile_mock_8', se8 , `F1sesubdecile_mock_8', p_value8, `p_valuesubdecile_mock_8') 




**************************************
*	Table A19
**************************************

local early  first_exam mean_exam
local i=1
foreach x of local early { 
reghdfe  std_POINTS2 POINTS2_mock  treatment school1-school11 treatment_`x' `x' ${controls}, $reghdfe vce(robust)
lincom treatment+treatment_`x'
local F1c = r(estimate)
local F1se = r(se)
test  treatment_`x' + treatment =0
local p_value=r(p)
if `i'==1 {
outreg2 using "${output}/table_A19.tex", dec(2) title(Impact of treatment assignment on standardized test scores) keep(std_POINTS2 treatment treatment_`x' `x' ${controls}) addstat(treated, `F1c', SE , `F1se', p_value, `p_value')  replace
}
else {
outreg2 using "${output}/table_A19.tex", dec(2) title(Impact of treatment assignment on standardized test scores) keep(std_POINTS2 treatment treatment_`x' `x' ${controls}) addstat(treated, `F1c', SE , `F1se', p_value, `p_value') 
}
reghdfe std_principal2 std_principal2_mock std_principal2_mock_miss treatment school1-school11 treatment_`x' `x' ${controls}, $reghdfe vce(robust)
lincom treatment+treatment_`x'
local F1c = r(estimate)
local F1se = r(se)
test  treatment_`x' + treatment =0
local p_value=r(p)
outreg2 using "${output}/table_A19.tex", dec(2) title(Impact of treatment assignment on standardized test scores) keep(std_principal2 treatment treatment_`x' `x' ${controls}) addstat(treated, `F1c', SE , `F1se', p_value, `p_value') 

reghdfe std_subsidiary2 std_subsidiary2_mock std_subsidiary2_mock_miss treatment school1-school11 treatment_`x' `x' ${controls}, $reghdfe vce(robust)
lincom treatment+treatment_`x'
local F1c = r(estimate)
local F1se = r(se)
test  treatment_`x' + treatment =0
local p_value=r(p)
outreg2 using "${output}/table_A19.tex", dec(2) title(Impact of treatment assignment on standardized test scores) keep(std_subsidiary2 treatment treatment_`x' `x' ${controls3}) addstat(treated, `F1c', SE , `F1se', p_value, `p_value') 

reghdfe uni_pass treatment school1-school11 treatment_`x' `x' ${controls} POINTS2_mock, $reghdfe vce(robust)
sum uni_pass if `x'==1 & treatment==0
local mean=r(mean)
lincom treatment+treatment_`x'
local F1c = r(estimate)
local F1se = r(se)
test  treatment_`x' + treatment =0
local p_value=r(p)
outreg2 using "${output}/table_A19.tex", dec(2) title(Impact of treatment assignment on standardized test scores) keep(uni_pass treatment treatment_`x' `x' ${controls3}) addstat(treated, `F1c', SE , `F1se', p_value, `p_value', control mean, `mean') 
local i=`i'+1
}



**************************************
*	Table A21
**************************************
local subgroup  top_200   high_fees  
foreach y of local subgroup  {
capture gen treatment_`y'=treatment*`y'
}

preserve 
foreach y of local subgroup  {
local i=1
tempfile tf`y'`i' 
reghdfe std_POINTS2 treatment  treatment_`y' `y' ${controls}  POINTS2_mock school1-school11, vce(robust) $reghdfe
parmest, format(p %12.9f) saving(`tf`y'`i'',replace) idn(`i')

local i=`i'+1
tempfile tf`y'`i' 
reghdfe std_principal2 treatment  treatment_`y' `y' ${controls} std_principal2_mock std_principal2_mock_miss school1-school11, vce(robust) $reghdfe
parmest, format(p %12.9f) saving(`tf`y'`i'',replace) idn(`i')

local i=`i'+1
tempfile tf`y'`i' 
reghdfe std_subsidiary2 treatment  treatment_`y' `y' ${controls} std_subsidiary2_mock std_subsidiary2_mock_miss school1-school11, vce(robust) $reghdfe
parmest, format(p %12.9f) saving(`tf`y'`i'',replace) idn(`i')

}

local j=1
foreach y of local subgroup  {
dsconcat `tf`y'1' `tf`y'2' `tf`y'3'  
keep if parm=="treatment_`y'"
keep p idnum
qqvalue p, method(yekutieli) qvalue(q)
replace q=0.99 if q==1
format q %12.0g
*qqvalue p, method(bonferroni) qvalue(q2)
foreach x of numlist 1/3 {
global Tbq`j'`x'=q[`x']
display ${Tbq`j'`x'}
}

dsconcat `tf`y'1' `tf`y'2' `tf`y'3'  
keep if parm=="treatment"
keep p idnum
qqvalue p, method(yekutieli) qvalue(q)
replace q=0.99 if q==1
format q %12.0g
*qqvalue p, method(bonferroni) qvalue(q2)
foreach x of numlist 1/3 {
global Tq`j'`x'=q[`x']
display ${Tq`j'`x'}
}
local j=`j'+1
}

restore

local i=1 
foreach x of local subgroup { 
reghdfe std_POINTS2 treatment  treatment_`x' `x' ${controls}  POINTS2_mock school1-school11, vce(robust) $reghdfe
lincom treatment_`x' + treatment
local F1c = r(estimate)
local F1se = r(se)
test  treatment_`x' + treatment = 0
local p_value=r(p)
if `i'==1 {
outreg2 using "${output}/Table_A21.tex", dec(2) title(Impact of treatment assignment on standardized test scores) keep(std_POINTS2 treatment treatment_`x' `x') adec(2) addstat(var, `F1c', se, `F1se', pval, `p_value', qvalue interaction, ${Tbq`i'1}, qvalue, ${Tq`i'1}) replace
}
else {
outreg2 using "${output}/Table_A21.tex", dec(2) title(Impact of treatment assignment on standardized test scores) keep(std_POINTS2 treatment treatment_`x' `x') adec(2) addstat(var, `F1c', se, `F1se', pval, `p_value', qvalue interaction, ${Tbq`i'1}, qvalue, ${Tq`i'1})

}
reghdfe std_principal2 treatment  treatment_`x' `x' ${controls} std_principal2_mock std_principal2_mock_miss school1-school11, vce(robust) $reghdfe
lincom treatment_`x' + treatment
local F1c = r(estimate)
local F1se = r(se)
test  treatment_`x' + treatment = 0
local p_value=r(p)
outreg2 using "${output}/Table_A21.tex", dec(2) title(Impact of treatment assignment on standardized test scores) keep(std_principal2 treatment treatment_`x' `x' ) adec(2) addstat(var, `F1c', se, `F1se', pval, `p_value', qvalue interaction, ${Tbq`i'2}, qvalue, ${Tq`i'2}) 

reghdfe std_subsidiary2 treatment  treatment_`x' `x' ${controls} std_subsidiary2_mock std_subsidiary2_mock_miss school1-school11, vce(robust) $reghdfe
lincom treatment_`x' + treatment
local F1c = r(estimate)
local F1se = r(se)
test  treatment_`x' + treatment = 0
local p_value=r(p)
outreg2 using "${output}/Table_A21.tex", dec(2) title(Impact of treatment assignment on standardized test scores) keep(std_subsidiary2 treatment treatment_`x' `x'  ) adec(2) addstat(var, `F1c', se, `F1se', pval, `p_value', qvalue interaction, ${Tbq`i'3}, qvalue, ${Tq`i'3}) 

}




**************************************
*	Table A23
**************************************

permute treatment _b[treatment], rep(1000): reghdfe std_POINTS2 treatment POINTS2_mock school1-school11 , vce(robust) $reghdfe //0.010
permute treatment _b[treatment], rep(1000): reghdfe std_principal2 treatment std_principal2_mock  school1-school11, vce(robust) $reghdfe  //0.008
permute treatment _b[treatment], rep(1000): reghdfe std_subsidiary2 treatment std_subsidiary2_mock school1-school11 , vce(robust) $reghdfe  // 0.013)

reghdfe std_POINTS2 treatment school1-school11 POINTS2_mock , vce(robust) $reghdfe
outreg2 using "${output}/table_A23.tex", dec(2) title(Impact of treatment assignment on standardized test scores) keep(std_POINTS2 treatment) replace pval addstat(permutation test, 0.008)
reghdfe std_principal2 treatment school1-school11 std_principal2_mock std_principal2_mock_miss , vce(robust) $reghdfe
outreg2 using "${output}/table_A23.tex", dec(2) title(Impact of treatment assignment on standardized test scores) keep(std_principal2 treatment ) addstat(permutation test, 0.008)
reghdfe std_subsidiary2 treatment school1-school11 std_subsidiary2_mock std_subsidiary2_mock_miss , vce(robust) $reghdfe
outreg2 using "${output}/table_A23.tex", dec(2) title(Impact of treatment assignment on standardized test scores) keep(std_subsidiary2 treatment ) addstat(permutation test, 0.013)


